#ifndef MOTOR_DEF_H
#define MOTOR_DEF_H

#include "stdint.h"
#include "bsp_can.h"
#include "controller.h"

#define RPM_2_ANGLE_PER_SEC 6.0f
/* 闭环类型*/
typedef enum
{
    OPEN_LOOP = 0b0000,
    CURRENT_LOOP = 0b0001,
    SPEED_LOOP = 0b0010,
    ANGLE_LOOP = 0b0100,

    SPEED_AND_CURRENT_LOOP = 0b0011,
    ANGLE_AND_CURRENT_LOOP = 0b0101,
    THREE_LOOP = 0b0111,
} Loop_Type_e;

/* 反馈来源 */
typedef enum
{
    MOTOR_FEED = 0,
    OTHER_FEED,
} Feedback_Source_e;

/* 电机正反转标志 */
typedef enum
{
    MOTOR_DIRECTION_NORMAL = 0,
    MOTOR_DIRECTION_REVERSE = 1
} Motor_Reverse_Flag_e;

/* 电机工作状态 */
typedef enum
{
    MOTOR_STOP = 0,
    MOTOR_ENABLE = 1,
} Motor_Working_Type_e;

/* 电机控制器配置 */
typedef struct
{
    Loop_Type_e loop_type;
    Feedback_Source_e angle_feedback_source;
    Feedback_Source_e speed_feedback_source;
    Motor_Reverse_Flag_e motor_direction;
} Motor_Control_Config_s;

/* 电机控制器 */
typedef struct
{
    float* other_angle_feedback;
    float* other_speed_feedback;
    float* motor_angle_feedback;
    float* motor_speed_feedback;

    PIDInstance current_pid;
    PIDInstance speed_pid;
    PIDInstance angle_pid;

    float pid_ref;
} Motor_Control_s;

/* 电机类型 */
typedef enum
{
    MOTOR_TYPE_NONE = 0,
    M3508,
    M2006,
    M6020,
    DM4310,
    DM4330,
} Motor_Type_e;

typedef struct
{
    float* other_angle_feedback;
    float* other_speed_feedback;
    
    PID_Init_Config_s current_pid_config;
    PID_Init_Config_s speed_pid_config;
    PID_Init_Config_s angle_pid_config;
} Motor_Control_Init_s;

typedef struct
{
    Motor_Control_Init_s motor_init_config;
    Motor_Control_Config_s motor_control_init_config;
    Motor_Type_e motor_type;
    CAN_Init_Config_s can_init_config;
} Motor_Init_Config_s;


#endif
